package com.example.shop_2302.adapter

import android.widget.CheckBox
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.base.entity.Car
import com.example.shop_2302.R
import com.example.shop_2302.utils.GlideUtils

class CarAdapter:BaseQuickAdapter<Car,BaseViewHolder>(R.layout.item_car) {
    override fun convert(holder: BaseViewHolder, item: Car) {
        /***选中状态也要赋值，不然点击全选时，rv中的状态不会被选中**/
        holder.getView<CheckBox>(R.id.car_cb).isChecked = item.isCheck

        GlideUtils.loadCorner(context,item.image,holder.getView(R.id.car_image),10)

        holder.setText(R.id.car_storename,item.storeName)

        holder.setText(R.id.car_sku,"属性：${item.suk}")

        holder.setText(R.id.car_price,"￥${item.price}")

        holder.setText(R.id.car_num,"${item.cartNum}")

        //当购物车数量为1时，减号不可用
        if(item.cartNum==1){
            holder.getView<TextView>(R.id.car_sub).isEnabled = false
        }else{
            holder.getView<TextView>(R.id.car_sub).isEnabled = true
        }
    }
}